﻿/*
 * Returns a string that right-aligns the characters in the specified string by padding them with spaces on the left, 
 * for a specified total length.
 */
create function [String].[PadLeft] ( @p_String nvarchar(max), @p_TotalWidth int, @p_PaddingString nvarchar(max) = '0' )
returns nvarchar(max) as 
begin

  return Right( Replicate( @p_PaddingString, @p_TotalWidth ) + @p_String, @p_TotalWidth );

end